package cn.finder0519.applist;

import android.app.UiModeManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Build;

public class Utils {
    public static boolean isTvDevice(Context context) {
        UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
        boolean isTVMode = uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;

        PackageManager pm = context.getPackageManager();
        boolean hasLeanback = pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            hasLeanback = pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK) ||
                    pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY);
        }

        return isTVMode || hasLeanback;
    }
}
